home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / GRAPHICS.SWG / 0002_Drawing DOOM-like floors.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  5.2 KB  |  144 lines

  1.  
  2. {This is my procedure for drawing DOOM-like floors for the game I am working
  3. on. It uses the similar triangle method, but does not work as fast as I
  4. would like. The problem is probably that I am using Turbo Pascal.  I tried to 
  5. optimize using assembler, but have never used it before.   If anyone could 
  6. help me speed it up, I would really appreciate it. I think this procedure runs 
  7. at about 11-12 fps without my wall,objects procedures, at about 8 fps with 
  8. them.  The wall,objects procedures run at about 20 fps without the floor 
  9. procedure.  My goal is for a nice 15 fps with everything.  All speeds are on a 
  10. 486 DX2/66.
  11.  
  12.  
  13.  
  14. Sorry for the sloppy code. I'll try to explain.}
  15.  
  16.  
  17.  
  18. procedure floorcast(var player1:player);
  19. var
  20.    xp,yp:integer;       {some of these variables might not be needed}
  21.    z:word;
  22.    i:byte;
  23.    dd:longint;
  24.    xstep,ystep:longint;
  25.    scrd:integer;
  26.    finx1,finy1:longint;
  27.    finx2,finy2:integer;
  28.    finxd,finyd:longint;
  29.    distance:longint;
  30.    cc,colour:byte;
  31.    ssofs:word;
  32.    s3,o3,o4,s4:word;
  33.    mapx,mapy,bmapx,bmapy:byte;
  34.    ang:integer;
  35.    v1,v2:longint;
  36.    lookm:integer;
  37.    flm:byte;
  38.    loop:integer;
  39.    ssinc:byte;
  40.    zinc:word;
  41.    hh:word;
  42.    shade:byte;
  43.    cos2,sin2,cos1,sin1:longint;
  44.    sf:byte;
  45. begin
  46. v1:=viewcos^[0];                {to fix the fishbowl effect}
  47. v2:=viewcos^[319];
  48. lookm:=(player1.look-100); {to find out if the player is looking up or down}
  49. loop:=(player1.look+1);    {number of h-lines to draw}
  50. hh:=(vdis)*player1.height;  {viewer distance * player height}
  51. ang:=dangle(0,-dangle(player1.angle,(-160)));  {angle for left most pixel}
  52. cos1:=cost^[ang]; {trig values for angle}
  53. sin1:=sint^[ang];
  54. ang:=dangle(0,-dangle(player1.angle,(160)));  {angle for right most pixel}
  55. cos2:=cost^[ang]; {trig values for angle}
  56. sin2:=sint^[ang];
  57. ssofs:=320*loop+o1+xmin;  {screen offset at start of loop}
  58. ssinc:=xmin+320-xmax;     {screen offset increment to start each h-line}
  59. zinc:=xmax-xmin;          {size of h-viewport}
  60. emsmap(handle,0,0);       {ems routines for graphics}
  61. emsmap(handle,1,1);
  62. emsmap(handle,2,2);
  63. emsmap(handle,3,3);
  64. for i:=loop to toomax do  {loop from horizon to bottom of screen}
  65. begin
  66.      dd:=(hh div (i-player1.look)); {temp distance variable used twice}
  67.      distance:=(dd*v1) shr 16;      {fishbowl adjust}
  68.      distance:=(distance*5) shr 2;  {This fixes a strange floor shift for me}
  69.      distance:=distance-lookm;      {adjust for looking up or down}
  70.      finx1:=((distance*cos1)) shr 16; {rotate to player angle}
  71.      finy1:=(-(distance*sin1)) shr 16;
  72.  
  73.      distance:=(dd*v2) shr 16;         {same as above for right most pixel}
  74.      distance:=(distance*5) shr 2;
  75.      distance:=distance-lookm;
  76.      finx2:=((distance*cos2)) shr 16;
  77.      finy2:=(-(distance*sin2)) shr 16;
  78.  
  79.      finxd:=(finx2-finx1);  {x-distance}
  80.      finyd:=(finy2-finy1);  {y-distance}
  81.      finx1:=finx1+player1.x; {translate to player position}
  82.      finy1:=finy1+player1.y;
  83.      xstep:=(finxd shl 16) div 320;  {x-step along map for each pixel}
  84.      ystep:=(finyd shl 16) div 320;  {x-step along map for each pixel}
  85.      finx1:=finx1 shl 16;
  86.      finy1:=finy1 shl 16;
  87.      z:=ssofs+zinc;  {value for end of loop}
  88.      finx1:=(finx1+xstep*xmin); { adjust for variable screen size}
  89.      finy1:=(finy1+ystep*xmin);
  90.      repeat
  91.           if mem[s1:o1+ssofs]=0 then {if a wall or object has not been drawn}
  92.           begin
  93.           xp:=finx1 shr 16;  {fixed point shift}
  94.           yp:=finy1 shr 16;
  95.           asm
  96.              mov ax,xp       {map position}
  97.              shr ax,6
  98.              mov mapx,al
  99.              mov ax,yp
  100.              shr ax,6
  101.              mov mapy,al
  102.              mov ax,xp       {bitmap position}
  103.              and ax,3Fh
  104.              mov bmapx,al
  105.              mov ax,yp
  106.              and ax,3Fh
  107.              mov bmapy,al
  108.           end;
  109.           if (mapx>25) or (mapx<=0) or (mapy>25) or (mapy<=0) then
  110.           colour:=8   {check if out of bounds, I have a small map}
  111.           else
  112.           begin
  113.           colour:=floormap^[mapx,mapy]; {else find colour in map}
  114.           flm:=flipmap^[mapx,mapy];     {check if I should flip the bitmap}
  115.           if flm=0 then
  116.           begin
  117.           end
  118.           else if flm=1 then bmapx:=63-bmapx
  119.           else if flm=2 then bmapy:=63-bmapy
  120.           else if flm=3 then
  121.           begin
  122.                bmapx:=63-bmapx;
  123.                bmapy:=63-bmapy;
  124.           end;
  125.           end;
  126.           if bmapy>62 then bmapy:=62;
  127.           o4:=bmapx+((bmapy) shl 6)+ctable[colour];  {find the offset of the}
  128.           asm                                        {pixel in the bitmap}
  129.              mov es,[segment]
  130.              mov bx,[o4]
  131.              mov dl,byte ptr [es:bx]                {put it on the screen}
  132.              mov es,[s1]
  133.              mov bx,[ssofs]
  134.              mov byte ptr [es:bx],dl
  135.           end;
  136.           end;
  137.           ssofs:=ssofs+1;                     {increment screen offset}
  138.           finx1:=finx1+xstep;                 {step along map}
  139.           finy1:=finy1+ystep;
  140.      until ssofs=z;                             {until end of h-line}
  141.      ssofs:=ssofs+ssinc;                        {move down one h-line}
  142.      end;
  143. end;
  144.